<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="分析项目" prop="fxxm">
        <el-input v-model="queryParams.fxxm" placeholder="请输入分析项目" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="报告日期" prop="bgrq">
        <el-date-picker :editable="false" clearable size="small" v-model="queryParams.bgrq" type="date" value-format="yyyy-MM-dd" placeholder="选择报告日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产批次" prop="scpc">
        <el-input v-model="queryParams.scpc" placeholder="请输入生产批次" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['Laboratory_sensory:sensory:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['Laboratory_sensory:sensory:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['Laboratory_sensory:sensory:remove']">删除</el-button>
      </el-col>
      <!--   <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Laboratory_sensory:sensory:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="multiple" @click="handleCheck" v-hasPermi="['Laboratory_sensory:sensory:check']">审核</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sensoryList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" width="50px" />
      <el-table-column label="检测日期" align="center" prop="jcrq" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jcrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分析项目" align="center" prop="fxxm" :formatter="laboratory_Sensory_fxxm_Format" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.fxxm }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测依据" align="center" prop="jcyj" :formatter="laboratory_Sensory_jcyj_Format" width="200px">
        <template slot-scope="scope">
          <span>{{ scope.row.jcyj }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产批次" align="center" prop="scpc" />
      <el-table-column label="报表编号" align="center" prop="bbbh" width="200px" />
      <!-- <el-table-column label="试验环境 温度：℃" align="center" prop="wd" />
      <el-table-column label="试验环境 湿度：%" align="center" prop="sd" /> -->
      <el-table-column label="报告日期" align="center" prop="bgrq" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bgrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验人" align="center" prop="jyr" />
      <el-table-column label="审核人" align="center" prop="shrPerson" />

      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="250px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
          >导出</el-button            >
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" :disabled="scope.row.shrPerson" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['Laboratory_sensory:sensory:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['Laboratory_sensory:sensory:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改感官检验对话框 -->
    <el-dialog fullscreen v-myFullscreen :title="title" :visible.sync="open" width="1200px" append-to-body custom-class="myDialog">
      <TableHeader @nameChange="nameChange" :data="{
          mainTitle: '感官、净含量、电导率、溴酸盐出厂检验原始记录(矿、山)',
          company: '青岛崂山矿泉水有限公司',
          code: form.bbbh,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="分析项目" prop="fxxmsz">
              <!-- <el-input v-model="form.fxxm" placeholder="请输入分析项目" :disabled="openDisabled" /> -->
              <el-checkbox-group v-model="form.fxxmsz">
                <el-checkbox v-for="dict in laboratory_Sensory_fxxm" :label="dict.dictLabel" :key="dict.dictValue"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检测依据" prop="jcyjsz">
              <!-- <el-input v-model="form.jcyj" placeholder="请输入检测依据" :disabled="openDisabled" /> -->
              <!-- <el-checkbox-group v-model="form.jcyjsz">
                <el-checkbox
                  v-for="dict in laboratory_Sensory_jcyj"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                ></el-checkbox>
              </el-checkbox-group> -->

              <el-checkbox-group v-model="form.jcyjsz">
                <el-checkbox v-for="dict in laboratory_Sensory_jcyj" :label="dict.dictLabel" :key="dict.dictValue"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检测日期" prop="jcrq">
              <el-date-picker :editable="false" clearable v-model="form.jcrq" type="date" value-format="yyyy-MM-dd" placeholder="选择检测日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告日期" prop="bgrq">
              <el-date-picker :editable="false" clearable v-model="form.bgrq" type="date" value-format="yyyy-MM-dd" placeholder="选择报告日期" :disabled="openDisabled">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-row>
              <el-col :span="12">
                <el-form-item label="实验环境温度:℃" prop="wd">
                  <el-input v-model="form.wd" placeholder="请输入温度：℃" :disabled="openDisabled" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="湿度:%" prop="sd" label-width="60px">
                  <el-input v-model="form.sd" placeholder="请输入湿度：%" :disabled="openDisabled" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产批次" prop="scpc">
              <el-input v-model="form.scpc" placeholder="请输入生产批次" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 检验项目 -->
          <el-col :span="3">
            <el-form-item label="检验项目" label-width="80px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="滋味和气味" label-width="90px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="状态" label-width="60px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="色度(度)" label-width="80px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label="浊度(NTU)" label-width="110px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="净含量1(ml)" label-width="90px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="净含量2(ml)" label-width="90px" />
          </el-col>
          <el-col :span="3">
            <el-form-item label="电导率(μS/cm)" label-width="130px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label="溴酸盐（mg/L）" label-width="130px" />
          </el-col>
        </el-row>
        <el-row>
          <!-- 检验条件 -->
          <el-col :span="3">
            <el-form-item label="检验条件" label-width="110px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="嗅气和尝味法" label-width="90px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="直接观察法" label-width="60px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="铂-钴标准比色法" label-width="80px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label-width="1px">
              <el-radio v-model="form.zd" label="散射法-福尔马肼标准" @change="turbidity1" :disabled="openDisabled">散射法-福尔马肼标准</el-radio>
              <el-radio v-model="form.zd" label="目视比浊法-福尔马肼标准" @change="turbidity2" :disabled="openDisabled">目视比浊法-福尔马肼标准</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label="≤2L体积法" label-width="90px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="＞2L称量法" label-width="90px" />
          </el-col>
          <el-col :span="3">
            <el-form-item label="电极法" label-width="90px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label-width="5px">
              <el-radio v-model="form.xsy" label="GB8538-2022" :disabled="openDisabled">GB8538-2022</el-radio>
              <el-radio v-model="form.xsy" label="GB/T5750-2006" :disabled="openDisabled">GB/T5750-2006</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 取样量（ml） -->

          <el-col :span="3">
            <el-form-item label="取样量（ml）" label-width="110px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="100mL" label-width="80px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="--" label-width="60px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="50mL" label-width="80px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label="100mL" label-width="110px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="--" label-width="60px" />
          </el-col>
          <el-col :span="2">
            <el-form-item label="--" label-width="60px" />
          </el-col>
          <el-col :span="3">
            <el-form-item label="--" label-width="70px" />
          </el-col>
          <el-col :span="4">
            <el-form-item label="2mL" label-width="100px" />
          </el-col>
          <!-- <el-col :span="12">
              <el-form-item label="审核人" prop="shrPerson">
                <el-input v-model="form.shrPerson" placeholder="请输入审核人" :disabled="openDisabled" />
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="检验人" prop="jyr">
                <el-input v-model="form.jyr" placeholder="请输入检验人" :disabled="openDisabled" />
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="报表编号" prop="bbbh">
                <el-input v-model="form.bbbh" placeholder="请输入报表编号" :disabled="openDisabled" />
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" placeholder="请输入备注" :disabled="openDisabled" />
              </el-form-item>
          </el-col> -->
        </el-row>

        <br />
        <el-divider content-position="center">感官检验子信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddQualityLabSensorySub" :disabled="openDisabled">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteQualityLabSensorySub" :disabled="openDisabled">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="duplication1" :disabled="openDisabled">复制</el-button>
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table max-height="550" :data="qualityLabSensorySubList" :row-class-name="rowQualityLabSensorySubIndex" border @selection-change="handleQualityLabSensorySubSelectionChange" ref="qualityLabSensorySub" show-summary :summary-method="getSummaries">
          <el-table-column type="selection" width="50" align="center" />
          <!-- <el-table-column label="序号" align="center" prop="index" width="50"/> -->

          <el-table-column label="样品名称" prop="ypmc" min-width="280">
            <template slot-scope="scope">
              <!-- <el-input
                v-model="scope.row.ypmc"
                placeholder="请输入样品名称"
                :disabled="openDisabled"
              /> -->
              <Dialog @dialogChange="dialogChange($event, scope)" :echoValue="scope.row.ypmc" parameter="rows" value="id" label="name" :multiple="false" search="name/code" url="/basic/productInfo/listSelect" :column="['产成品编号/code', '产成品名称/name']" placeholder="请选择内容" :axiosData="{ typeCode: 'YYTRKQS' }" :openDisabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="产品编号" prop="cpbh" min-width="220">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cpbh" placeholder="请输入产品编号" :disabled="openDisabled" />
            </template>
          </el-table-column>

          <el-table-column label="气味分析" prop="qwfx">
            <template slot-scope="scope">
              <el-input v-model="scope.row.qwfx" placeholder="请输入气味分析" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="滋味分析" prop="zwfx">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zwfx" placeholder="请输入滋味分析" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="zt">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zt" placeholder="请输入状态" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="色度" prop="sd">
            <template slot-scope="scope">
              <el-input v-model="scope.row.sd" placeholder="请输入色度" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="浊度" prop="zd">
            <template slot-scope="scope">
              <el-input v-model="scope.row.zd" placeholder="请输入浊度" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="净含量≤2L 体积法" prop="jhlx2" width="160">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jhlx2" placeholder="请输入净含量≤2L 体积法" :disabled="openDisabled" type="number" />
            </template>
          </el-table-column>
          <el-table-column label="净含量>2L 称量法" prop="jhld2" width="160">
            <template slot-scope="scope">
              <el-input v-model="scope.row.jhld2" placeholder="请输入净含量>2L 称量法" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="电导率" prop="ddl">
            <template slot-scope="scope">
              <el-input v-model="scope.row.ddl" placeholder="请输入电导率" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="溴酸盐" prop="xsy">
            <template slot-scope="scope">
              <el-input v-model="scope.row.xsy" placeholder="请输入溴酸盐" :disabled="openDisabled" />
            </template>
          </el-table-column>
          <!-- <el-table-column label="报表编号" prop="bbbh">
            <template slot-scope="scope">
                <el-input v-model="scope.row.bbbh" placeholder="请输入报表编号" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
                <el-input v-model="scope.row.remark" placeholder="请输入备注" :disabled="openDisabled"/>
            </template>
          </el-table-column> -->
        </el-table>
        <el-row class="mb8">
          <div label="备注">
            备注:&nbsp;&nbsp;
            “滋味和气味”按照检测结果的等级填写(0级~5级)，超出0级需要立即上报品控主管；状态根据实际填写，其他项目填写实测值。
          </div>
        </el-row>
        <el-divider content-position="center"></el-divider>

        <el-row type="flex" justify="center">
          <el-col :span="12">
            <el-form-item label="审核人" prop="shrPerson">
              <el-input v-model="form.shrPerson" placeholder="请输入审核人" :disabled="true" style="width: 25%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="检验人" prop="jyr">
              <el-select v-model="form.jyr" filterable allow-create placeholder="请选择检验人" style="width: 25%" :disabled="openDisabled">
                <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName" :disabled="openDisabled"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSensory,
  getSensory,
  delSensory,
  addSensory,
  updateSensory,
  verifySensory,
} from "@/api/quality/laboratory/sensory";
import { getInfo } from "@/api/login";
import { listUser } from "@/api/system/user";

export default {
  name: "Sensory",
  data() {
    return {
      laboratory_Sensory_fxxm: [],
      laboratory_Sensory_jcyj: [],
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedQualityLabSensorySub: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 感官检验表格数据
      sensoryList: [],
      // 感官检验子表格数据
      qualityLabSensorySubList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        fxxm: null,
        bgrq: null,
        scpc:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      /* 当前用户名 */
      nickName: "",
      userList: [],
      zd: null,
    };
  },
  created() {
    this.getList();
    this.queryUserList();
    this.getDicts("laboratory_Sensory_fxxm").then((response) => {
      this.laboratory_Sensory_fxxm = response.data;
    });
    this.getDicts("laboratory_Sensory_jcyj").then((response) => {
      this.laboratory_Sensory_jcyj = response.data;
    });
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 2) {
          sums[index] = "平均值";
          return;
        } else if (index == 8) {
          const values = data.map((item) => Number(item[column.property]));
          let num = 0;
          let sum = 0;
          values.forEach((item) => {
            let n = Number(item);
            if (n != 0) {
              num++;
              sum += n;
            }
          });
          if (num != 0) {
            sums[index] = (sum / num).toFixed(1);
          }
          return;
        } else if (index == 10) {
          const values = data.map((item) => Number(item[column.property]));
          let num = 0;
          let sum = 0;
          values.forEach((item) => {
            let n = Number(item);
            if (n != 0) {
              num++;
              sum += n;
            }
          });
          if (num != 0) {
            sums[index] = (sum / num).toFixed(1);
          }
          return;
        } else {
          sums[index] = "--";
        }
      });

      return sums;
    },
    // 复制最后一行
    duplication1() {
      let arr = this.qualityLabSensorySubList;
      let obj = arr[arr.length - 1];
      var obj1 = JSON.parse(JSON.stringify(obj));
      this.qualityLabSensorySubList.push(obj1);
    },
    dialogChange(event, scope) {
      this.qualityLabSensorySubList[scope.$index].ypmc = event.label;
    },
    // 浊度
    turbidity1() {
      this.zd = "0";
      this.qualityLabSensorySubList.forEach((item) => {
        item.zd = "0";
      });
    },
    turbidity2() {
      this.zd = "<0.5";
      this.qualityLabSensorySubList.forEach((item) => {
        item.zd = "<0.5";
      });
    },
    /** 查询感官检验列表 */
    getList() {
      this.loading = true;
      listSensory(this.queryParams).then((response) => {
        this.sensoryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 故障类型字典翻译
    laboratory_Sensory_fxxm_Format(row, column) {
      return this.selectDictLabel(this.laboratory_Sensory_fxxm, row.fxxm);
    },
    laboratory_Sensory_jcyj_Format(row, column) {
      return this.selectDictLabel(this.laboratory_Sensory_jcyj, row.jcyj);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fxxmsz: [
          this.laboratory_Sensory_fxxm[0].dictLabel,
          this.laboratory_Sensory_fxxm[1].dictLabel,
          this.laboratory_Sensory_fxxm[2].dictLabel,
          this.laboratory_Sensory_fxxm[3].dictLabel,
        ],
        fxxm: null,
        jcyj: null,
        jcyjsz: [],
        jcrq: null,
        bgrq: null,
        wd: null,
        sd: null,
        zd: null,
        xsy: null,
        scpc: null,
        shrPerson: null,
        jyr: this.nickName,
        bbbh: "LK-QF-LS1-10-015-11-05",
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
      };
      this.qualityLabSensorySubList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加感官检验";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getSensory(id).then((response) => {
        this.form = response.data;
        this.qualityLabSensorySubList = response.data.qualityLabSensorySubList;
        this.open = true;
        this.title = "修改感官检验";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getSensory(id).then((response) => {
        this.form = response.data;
        this.qualityLabSensorySubList = response.data.qualityLabSensorySubList;
        this.open = true;
        this.title = "查看感官检验";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.qualityLabSensorySubList = this.qualityLabSensorySubList;
            /**打开遮罩层*/
            const rLoading = this.openLoading();
          if (this.form.id != null) {
            updateSensory(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                /**请求异常后执行关闭遮罩层*/
                rLoading.close();
              });
          } else {
            addSensory(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                /**请求异常后执行关闭遮罩层*/
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除感官检验编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delSensory(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 感官检验子序号 */
    rowQualityLabSensorySubIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 感官检验子添加按钮操作 */
    handleAddQualityLabSensorySub() {
      let obj = {};
      obj.ypmc = "";
      obj.cpbh = "";

      const myDate = new Date();
      const year = myDate.getFullYear();
      const month = myDate.getMonth() + 1;
      const day = myDate.getDate() - 1;
      // obj.cpbh = `${year}-${month}-${day}`;
      obj.cpbh = '';

      obj.qwfx = "0级";
      obj.zwfx = "0级";
      obj.zt = "无";
      obj.sd = "<5";
      obj.zd = this.zd;
      obj.jhlx2 = "";
      obj.jhld2 = "-";
      obj.ddl = "";
      obj.xsy = "<0.005";
      obj.bbbh = "";
      obj.remark = "";
      this.qualityLabSensorySubList.push(obj);
    },
    /** 感官检验子删除按钮操作 */
    handleDeleteQualityLabSensorySub() {
      if (this.checkedQualityLabSensorySub.length == 0) {
        this.$alert("请先选择要删除的感官检验子数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.qualityLabSensorySubList.splice(
          this.checkedQualityLabSensorySub[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleQualityLabSensorySubSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.qualityLabSensorySub.clearSelection();
        this.$refs.qualityLabSensorySub.toggleRowSelection(selection.pop());
      } else {
        this.checkedQualityLabSensorySub = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "Laboratory_sensory/sensory/export",
        {
          ...this.queryParams,
        },
        `Laboratory_sensory_sensory.xlsx`
      );
    },
    excelhandleView(row){
      this.download(
        "Laboratory/sensory/exportexcel?id="+row.id,
        {
          ...this.queryParams,
        },
        "感官检验" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    //接收编号
    nameChange(e) {
      this.form.bbbh = e;
    },
    /* 合并两行 */
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },

    /** 审核按钮操作 */
    handleCheck(row) {
      //审核
      this.ids.forEach((id) => {
        getSensory(id).then((response) => {
          if (
            response.data.shrPerson != null &&
            response.data.shrPerson != ""
          ) {
            this.msgError(
              '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
            );
          } else {
            let obj = {};
            obj.id = id;
            obj.shrPerson = this.nickName;
            obj.qualityLabSensorySubList = this.qualityLabSensorySubList;
            // 修改
            verifySensory(obj).then((response) => {
              this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
              this.getList();
            });
          }
        });
      });
    },
    /* 查询用户列表 */
    queryUserList() {
      listUser().then((response) => {
        this.userList = response.rows;
      });
      getInfo().then((response) => {
        this.nickName = response.user.nickName;
      });
    },
  },
};
</script>
